package com.bree.erp.data.xls.imp;

import java.io.File;
import java.io.IOException;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import com.bree.erp.data.xls.imp.sheet.*;

import jxl.Workbook;
import jxl.read.biff.BiffException;

public class ImportMain {

	public static void main(String... argv) throws BiffException, IOException {

		String path = argv[0];
		Workbook workbook = Workbook.getWorkbook(new File(path));

		AbstractSheet[] sheets = { new UserSheet(workbook.getSheet("User")),
				new ProjectSheet(workbook.getSheet("Project")),
				new UnitSheet(workbook.getSheet("UOM")),
				new BrandSellerSheet(workbook.getSheet("BrandSeller")),
				new MasterListSheet(workbook.getSheet("MasterList")),
				new WarehouseSheet(workbook.getSheet("Warehouse")),
				new CurrencySheet(workbook.getSheet("Currency")),
				new SupplierSheet(workbook.getSheet("Supplier"))};

		EntityManagerFactory emf = Persistence
				.createEntityManagerFactory("Bree_Data");
		EntityManager em = emf.createEntityManager();

		for (AbstractSheet sheet : sheets) {

			sheet.importSheet(em);

		}

		// close the EM and EMF when done
		em.close();
		emf.close();

	}
}
